package com.denlaku.longan.service.impl;

import com.denlaku.longan.qo.DataPermQuery;
import com.denlaku.longan.qo.Query;
import com.denlaku.longan.repository.DataTagRepository;
import com.denlaku.longan.service.DataTagRelService;
import com.denlaku.longan.service.DataTagService;
import com.denlaku.longan.vo.DataTag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author tianx
 */
@Slf4j
@Service
public class DataTagServiceImpl implements DataTagService {
    @Autowired
    private DataTagRepository dataTagRepository;

    @Autowired
    private DataTagRelService dataTagRelService;

    @Override
    public void add(DataTag dataTag) {
        dataTagRepository.add(dataTag);
    }

    @Override
    public void update(DataTag dataTag) {
        dataTagRepository.update(dataTag);
    }

    @Override
    public DataTag get(Query query) {
        return dataTagRepository.get(query);
    }

    @Override
    public List<DataTag> list(DataPermQuery query) {
        return dataTagRepository.list(query);
    }

    @Override
    public List<DataTag> search(DataPermQuery query) {
        return dataTagRepository.search(query);
    }

    @Override
    public void delete(DataPermQuery query) {
        dataTagRepository.delete(query);
        query.setTagId(query.getId());
        query.setId(null);
        dataTagRelService.delete(query);
    }
}
